Skip to content

[FIXED] MQTT: Retained message body possibly corrupt in cluster mode#7622

Merged
neilalexander merged 1 commit intomainfrom
mqtt_retain_corrupt_body
Dec 8, 2025
Merged

[FIXED] MQTT: Retained message body possibly corrupt in cluster mode#7622
neilalexander merged 1 commit intomainfrom
mqtt_retain_corrupt_body

Conversation

@kozlovic
Copy link
Copy Markdown
Member

@kozlovic kozlovic commented Dec 6, 2025

When running in cluster mode, if a MQTT producer connects to server S-1 and sends a retained message on "foo", other servers in the cluster (say S-2) will be aware by having a consumer on the retained message stream.
If an MQTT subscription matching the retained message is started on S-2, that will make the retained message loaded into the cache.

If another retained message on that same subject is sent from S-1, then when consuming the message from the retained message stream, S-2 would replace the original retained message on "foo" by this new message, but the body would at the very least contain extra CR_LF ("\r\n") but could also contain some random data. This is because the message body was not properly cloned and would still reference an internal buffer (that may be reused).

Signed-off-by: Ivan Kozlovic ivan@synadia.com

When running in cluster mode, if a MQTT producer connects to server
S-1 and sends a retained message on "foo", other servers in the cluster
(say S-2) will be aware by having a consumer on the retained message
stream.
If an MQTT subscription matching the retained message is started
on S-2, that will make the retained message loaded into the cache.

If another retained message on that same subject is sent from S-1,
then when consuming the message from the retained message stream,
S-2 would replace the original retained message on "foo" by this
new message, but the body would at the very least contain extra
CR_LF ("\r\n") but could also contain some random data. This is
because the message body was not properly cloned and would still
reference an internal buffer (that may be reused).

Signed-off-by: Ivan Kozlovic <ivan@synadia.com>
@kozlovic kozlovic requested a review from a team as a code owner December 6, 2025 22:48
Copy link
Copy Markdown
Member

@neilalexander neilalexander left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@neilalexander neilalexander merged commit acc0a63 into main Dec 8, 2025
69 of 70 checks passed
@neilalexander neilalexander deleted the mqtt_retain_corrupt_body branch December 8, 2025 09:24
neilalexander added a commit that referenced this pull request Dec 11, 2025
Includes the following:

- #7622
- #7619
- #7624
- #7625
- #7627
- #7630
- #7631
- #7632

Signed-off-by: Neil Twigg <neil@nats.io>
neilalexander added a commit that referenced this pull request Dec 18, 2025
Includes the following:

- #7553
- #7555
- #7579
- #7578
- #7581
- #7585
- #7586
- #7588
- #7593
- #7594
- #7595
- #7596
- #7597
- #7598
- #7601
- #7604
- #7605
- #7610
- #7616
- #7614
- #7622
- #7619
- #7624
- #7625
- #7627
- #7636
- #7637
- #7643
- #7648
- #7634
- #7655
- #7656

Signed-off-by: Neil Twigg <neil@nats.io>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants